package com.cosina.game.crystallight.ui.menu.transform;

import android.graphics.Canvas;

import com.cosina.game.crystallight.util.World;

public class FlyTransform extends Transform {

	private int src = 0; 
	
	public void setFrom(int src){
		this.src = src;
		if(src == World.LEFT || src == World.TOP){
			offset = -350;
		}else{
			offset = 350;
		}
	}
	public int offset = 0;
	int speed = 40;
	
	
	public int delayCount = 0;
	
	@Override
	public void update(){
		if(delayCount > 0){
			delayCount = delayCount - 1;
			return ;
		}
		if(speed > 2)
			speed --;
		
		if(Math.abs(offset) <= 2){
			offset = 0;
		}else{
			if(offset > 0){
				offset -= speed;
			}else if(offset < 0){
				offset += speed;
			}
		}
	}
	
	@Override
	public void doT(Canvas canvas) {
		if(offset != 0){
			if(src == World.LEFT || src == World.RIGHT){
				canvas.translate(-offset, 0);
			}else{
				canvas.translate(0,-offset);
			}
		}
	}

	@Override
	public void undoT(Canvas canvas) {
		if(offset != 0){
			if(src == World.LEFT || src == World.RIGHT){
				canvas.translate(offset, 0);
			}else{
				canvas.translate(0,offset);
			}
		}
	}

}
